function ergodic(obj,indentation){
    var indent = "  " + indentation;
    if(obj.constructor == Array || obj.constructor == Object){
        for(var p in obj){
            if(obj[p].constructor == Array|| obj[p].constructor == Object){
                console.log(indent + "["+p+"] => "+typeof(obj)+"");
                console.log(indent + "{");
                ergodic(obj[p], indent);
                console.log(indent + "}");
            } else if (obj[p].constructor == String) {
                console.log(indent + "["+p+"] => "+obj[p]+"");
            } else {
                console.log(indent + "["+p+"] => "+obj[p]+"");
            }
        }
    }
}

function print_r(obj) {
    console.log("{")
    ergodic(obj, "");
    console.log("}")
}


function preg_match_all(regStr,str,nn){
    var arr=new Array();
    var objRegExp = new RegExp(regStr,"ig");
    while(res = objRegExp.exec(str)){
        arr.push(res);
    }
	for(var i in arr){
		nn[i]=arr[i];
	}
    return nn.length>0;
}

function preg_replace(regStr,str,str2){
    var arr=new Array();
    var objRegExp = new RegExp(regStr,"ig");
    str2=str2.replace(/\\([0-9]+)/g,"\$$1");
    str=str.replace(objRegExp,str2);
    return str;
}

var nn=new Array();
str=preg_replace("([0-9]+)","fds3fdsf54kfsd","\\1aa");
print_r(str);
console.log(str)
